iT邦幫忙

2022 iThome 鐵人賽

DAY 25
0

這次部屬Free5Gmano下的Kube5GNfvo專案。
首先clone Kube5GNfvo專案
git clone https://github.com/Free5Gmano/Kube5GNfvo.git

那麼第一步就是將相依件apply:

multus
https://ithelp.ithome.com.tw/upload/images/20220925/2012777630CUOkMr1d.png
multus用於解決k8s預設的POD不允許複數網卡的限制,multus可以為運行在kubernetes的POD提供多個網路介面,可以將多個CNI-Plugin組合並為POD配置不同類型的網路。

cd Kube5GNfvo/example/
kubectl apply -f multus-daemonset.yml

install OpenvSwitch並架設
OpenvSwitch是一種虛擬交換器,可用來作為L2的switch。
這裡因為VNF各元件內要互通,因此需要OpenvSwitch。

apt install openvswitch-switch -y
ovs-vsctl add-br br1

OVS-CNI

cd Kube5GNfvo/example/
kubectl apply -f ovs-cni.yaml

創建 NetworkAttachmentDefinition

cat <<EOF >./ovs-net-crd.yaml
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: ovs-net
  annotations:
    k8s.v1.cni.cncf.io/resourceName: ovs-cni.network.kubevirt.io/br1
spec:
  config: '{
      "cniVersion": "0.3.1",
      "type": "ovs",
      "bridge": "br1"
    }'
EOF
kubectl apply -f ovs-net-crd.yaml

Etcd Operator

cd Kube5GNfvo/example/etcd-cluster/rbac/
./create_role.sh
cd ..
kubectl apply -f deployment.yaml
(確認etcd的pod建立完畢後再進行下一步)
kubectl apply -f .

Metrics Server
新版K8S可以通過Metrics獲取資源使用情況(如container的CPU和memory使用情況等)。

cd Kube5GNfvo/example/metrics-server/
kubectl apply -f .

Node Exporter
node-exporter用於獲取UNIX類型的Kernal的硬體以及系統指標等。

cd Kube5GNfvo/example/
kubectl apply -f prom-node-exporter.yaml

KubeVirt

cd Kube5GNfvo/example/kubevirt/
kubectl apply -f kubevirt-operator.yaml
(確認kubevirt namespace建立成功後其內部所有pod都running之後再進行下一步驟)
kubectl apply -f kubevirt-cr.yaml

第二步是快速開始Kube5GNFVO

cat ~/.kube/config

將上面的輸出資料輸入下面的程式碼

cat <<EOF >./Kube5GNfvo-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: Kube5GNfvo-config
data:
  config: |
      # 貼在這裡,注意排版
EOF

kubectl apply -f Kube5GNfvo-configmap.yaml
Kube5GNfvo ServiceAccount
cat <<EOF >./Kube5GNfvo-sa.yaml
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: Kube5GNfvo
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: Kube5GNfvo
  namespace: default
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: Kube5GNfvo
EOF
kubectl apply -f Kube5GNfvo-sa.yaml

部屬MySQL資料庫

cat <<EOF >./Kube5GNfvo-mysql.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: Kube5GNfvo-mysql
spec:
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: Kube5GNfvo-mysql
  template:
    metadata:
      labels:
        app: Kube5GNfvo-mysql
    spec:
      containers:
      - image: mysql:5.6
        name: Kube5GNfvo-mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: Kube5GNfvo-mysql
          mountPath: /var/lib/mysql
        volumeMounts:
        - name: mysql-initdb
          mountPath: /docker-entrypoint-initdb.d
      volumes:
      - name: Kube5GNfvo-mysql
        persistentVolumeClaim:
          claimName: Kube5GNfvo-mysql
      volumes:
      - name: mysql-initdb
        configMap:
          name: mysql-initdb-config
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: Kube5GNfvo-mysql
  labels:
    name: Kube5GNfvo-mysql
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    type: DirectoryOrCreate
    path: /mnt/Kube5GNfvo-mysql
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: Kube5GNfvo-mysql
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  selector:
    matchExpressions:
    - key: name
      operator: In
      values: ["Kube5GNfvo-mysql"]
---
apiVersion: v1
kind: Service
metadata:
  name: Kube5GNfvo-mysql
spec:
  ports:
  - port: 3306
  selector:
    app: Kube5GNfvo-mysql
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-initdb-config
data:
  initdb.sql: |
    CREATE DATABASE Kube5GNfvo;
EOF

kubectl apply -f Kube5GNfvo-mysql.yaml

部署Kube5GNfvo本體

cat <<EOF >./Kube5GNfvo.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: Kube5GNfvo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: Kube5GNfvo
  template:
    metadata:
      labels:
        app: Kube5GNfvo
    spec:
      serviceAccountName: Kube5GNfvo
      containers:
      - image: Free5Gmano/Kube5GNfvo-stage2
        name: Kube5GNfvo
        env:
        - name: DATABASE_PASSWORD
          value: "password"
        - name: DATABASE_HOST
          value: "Kube5GNfvo-mysql"
        - name: DATABASE_PORT
          value: "3306"
        command: ["/bin/sh","-c"]
        args: ['python3 manage.py migrate && python3 manage.py runserver 0:8000']
        ports:
        - containerPort: 8000
          name: Kube5GNfvo
        volumeMounts:
        - name: Kube5GNfvo-vnf-package
          mountPath: /root/NSD
          subPath: NSD
        - name: Kube5GNfvo-vnf-package
          mountPath: /root/VnfPackage
          subPath: VnfPackage
        - name: kube-config
          mountPath: /root/config
          subPath: config
      volumes:
      - name: Kube5GNfvo-vnf-package
        persistentVolumeClaim:
          claimName: Kube5GNfvo-pvc
      - name: kube-config
        configMap:
          name: Kube5GNfvo-config
          items:
          - key: config
            path: config
---
apiVersion: v1
kind: Service
metadata:
  name: Kube5GNfvo
spec:
  type: NodePort
  ports:
  - port: 8000
    nodePort: 30888
  selector:
    app: Kube5GNfvo
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: Kube5GNfvo-pvc
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  selector:
    matchExpressions:
    - key: name
      operator: In
      values: ["Kube5GNfvo"]
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: Kube5GNfvo-pv
  labels:
    name: Kube5GNfvo
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    type: DirectoryOrCreate
    path: /mnt/Kube5GNfvo
EOF

kubectl apply -f Kube5GNfvo.yaml

上一篇
24-free5GC事先準備
下一篇
26-Kube5GNfvo演練
系列文
5哥窟-5G與肝臟買賣30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言